package org.topdowntdd.sample.appfusemodularstruts.webapp.action.person;

import org.topdowntdd.sample.appfusemodularstruts.model.Person;
import org.topdowntdd.sample.appfusemodularstruts.webapp.model.Page;

public class ViewAction extends BaseAction {

	private Long id;
	private Person person;
	private ViewAction _this = this;
	private Page page;

	public void setId(Long id) {
		this.id = id;
	}

	public void setSeam(ViewAction seam) {
		_this = seam;
	}
	
	public Page getPage() {
		return page;
	}

	public Person getPerson() {
		return person;
	}

	@Override
	public String execute() {
		if (id != null) {
			viewPersonInformation();
		} else {
			viewPersonForm();
		}
		return SUCCESS;
	}

	private void viewPersonInformation() {
		person = personManager.get(id);
		String title = _this.getText("person.view.title");
		String heading = _this.getText("person.view.heading");
		page = new Page(title, heading);
	}

	private void viewPersonForm() {
		String title = _this.getText("person.add.title");
		String heading = _this.getText("person.add.heading");
		page = new Page(title, heading);
	}

}
